package edu.guet.server.service.imple;

import edu.guet.server.mapper.ShowResourceMapper;
import edu.guet.server.mapper.ShowUnitMapper;
import edu.guet.server.model.vo.ResourceVO;
import edu.guet.server.service.ShowResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShowResourceServiceImpl implements ShowResourceService {

    @Autowired
    private ShowResourceMapper resourceMapper;

    @Override
    public List<ResourceVO> showResource(int unit_id) {
        // 获取子模块的unit_id
        List<Integer> subUnitIds = resourceMapper.findSubUnitIdsByUnitId(unit_id);
        if (subUnitIds == null || subUnitIds.isEmpty()) {
            return null;
        }

        // 获取子模块的resource_id
        List<Integer> resourceIds = resourceMapper.findResourceIdsBySubUnitIds(subUnitIds);
        if (resourceIds == null || resourceIds.isEmpty()) {
            return null;
        }

        // 获取资源详细信息
        return resourceMapper.findResourcesByResourceIds(resourceIds);
    }
}
